package controllers
{
	import models.LocalSetting;
	import models.vo.ChatMsgVO;
	import models.vo.UserVO;
	
	public class ChatController
	{
		[DexterBinding]
		public var localSetting:LocalSetting;
		[DexterEvent]
		public function sendChat(content:ChatMsgVO,user:UserVO):void{
			if(user == UserVO.all){
				sendDexterEvent("sendToOthers","chat",content,UserVO.self.id);
			}else{
				sendDexterEvent("sendToUser",user,"chatPrivate",content,UserVO.self.id);
			}
		}
		[DexterEvent]
		public function $chatPrivate(content:Object,from:String):void{
			var chatVO:ChatMsgVO = new ChatMsgVO(content);
			chatVO.time = new Date().toLocaleTimeString();
			var userVO:UserVO = sendDexterEvent("getUserByID",from);
			if(userVO){
				sendDexterEvent("receiveChatMsg",chatVO,userVO);
			}
		}
	}
}